/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import cn.hutool.json.JSONObject;
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.entity.DceInfo;
/*     */ import com.wgcloud.entity.DceState;
/*     */ import com.wgcloud.entity.SystemInfo;
/*     */ import com.wgcloud.service.DashboardService;
/*     */ import com.wgcloud.service.DceInfoService;
/*     */ import com.wgcloud.service.DceStateService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.service.SystemInfoService;
/*     */ import com.wgcloud.util.DateUtil;
/*     */ import com.wgcloud.util.PageUtil;
/*     */ import com.wgcloud.util.ResDataUtils;
/*     */ import com.wgcloud.util.TokenUtils;
/*     */ import com.wgcloud.util.license.LicenseUtil;
/*     */ import com.wgcloud.util.staticvar.StaticKeys;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/dceInfo"})
/*     */ public class DceInfoController
/*     */ {
/*  47 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.DceInfoController.class);
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DceInfoService dceInfoService;
/*     */   
/*     */   @Resource
/*     */   private SystemInfoService systemInfoService;
/*     */   
/*     */   @Resource
/*     */   private DceStateService dceStateService;
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */   
/*     */   @Resource
/*     */   private DashboardService dashboardService;
/*     */   
/*     */   @Autowired
/*     */   private TokenUtils tokenUtils;
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"agentList"})
/*     */   public String agentList(@RequestBody String paramBean) {
/*  72 */     if (!StaticKeys.LICENSE_STATE.equals("1")) {
/*  73 */       return ResDataUtils.resetErrorJson("请先升级到专业版");
/*     */     }
/*  75 */     JSONObject agentJsonObject = (JSONObject)JSONUtil.parse(paramBean);
/*  76 */     if (!this.tokenUtils.checkAgentToken(agentJsonObject)) {
/*  77 */       logger.error("token is error");
/*  78 */       return ResDataUtils.resetErrorJson("token is error");
/*     */     } 
/*  80 */     Map<String, Object> params = new HashMap<>();
/*     */     try {
/*  82 */       params.put("active", "1");
/*  83 */       List<DceInfo> dceInfoList = this.dceInfoService.selectAllByParams(params);
/*  84 */       return ResDataUtils.resetSuccessJson(dceInfoList);
/*  85 */     } catch (Exception e) {
/*  86 */       logger.error("agent获取数控设备监测信息错误", e);
/*  87 */       this.logInfoService.save("agent获取数控设备监测信息错误", e.toString(), "1");
/*  88 */       return ResDataUtils.resetErrorJson(e.toString());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String DceInfoList(DceInfo dceInfo, Model model, HttpServletRequest request) {
/* 101 */     Map<String, Object> params = new HashMap<>();
/*     */     
/*     */     try {
/* 104 */       LicenseUtil.maxLicense_10(model, request);
/*     */ 
/*     */       
/* 107 */       StringBuffer url = new StringBuffer();
/* 108 */       String hostName = null;
/* 109 */       String heathStatus = null;
/* 110 */       if (!StringUtils.isEmpty(dceInfo.getHostname())) {
/* 111 */         hostName = dceInfo.getHostname();
/* 112 */         params.put("hostname", hostName.trim());
/* 113 */         url.append("&hostname=").append(hostName);
/*     */       } 
/* 115 */       if (!StringUtils.isEmpty(request.getParameter("heathStatus"))) {
/* 116 */         heathStatus = request.getParameter("heathStatus");
/* 117 */         if ("200".equals(heathStatus)) {
/* 118 */           params.put("resTimesGt", Integer.valueOf(-1));
/*     */         }
/* 120 */         if ("500".equals(heathStatus)) {
/* 121 */           params.put("resTimes", Integer.valueOf(-1));
/*     */         }
/* 123 */         url.append("&heathStatus=").append(heathStatus);
/*     */       } 
/*     */       
/* 126 */       PageInfo<DceInfo> pageInfo = this.dceInfoService.selectByParams(params, dceInfo.getPage().intValue(), dceInfo.getPageSize().intValue());
/* 127 */       PageUtil.initPageNumber(pageInfo, model);
/* 128 */       model.addAttribute("pageUrl", "/dceInfo/list?1=1" + url.toString());
/* 129 */       model.addAttribute("page", pageInfo);
/* 130 */       model.addAttribute("dceInfo", dceInfo);
/* 131 */     } catch (Exception e) {
/* 132 */       logger.error("查询数通设备监测错误", e);
/* 133 */       this.logInfoService.save("查询数通设备监测错误", e.toString(), "1");
/*     */     } 
/* 135 */     return "dce/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"save"})
/*     */   public String saveDceInfo(DceInfo dceInfo, Model model, HttpServletRequest request) {
/* 149 */     String errorMsg = "保存数通设备监测错误";
/*     */     try {
/* 151 */       if (StringUtils.isEmpty(dceInfo.getId())) {
/* 152 */         this.dceInfoService.save(dceInfo);
/*     */       } else {
/* 154 */         this.dceInfoService.updateById(dceInfo);
/*     */       }
/*     */     
/* 157 */     } catch (Exception e) {
/* 158 */       logger.error(errorMsg, e);
/* 159 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 161 */     return "redirect:/dceInfo/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"importHosts"})
/*     */   public String importHosts() {
/*     */     try {
/* 173 */       Map<String, Object> map = new HashMap<>();
/* 174 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(map);
/* 175 */       List<DceInfo> dceInfoQueryList = this.dceInfoService.selectAllByParams(map);
/* 176 */       List<DceInfo> dceInfoSaveList = new ArrayList<>();
/*     */       
/* 178 */       boolean sign = false;
/* 179 */       for (SystemInfo systemInfo : systemInfoList) {
/* 180 */         DceInfo dceInfo = new DceInfo();
/* 181 */         dceInfo.setHostname(systemInfo.getHostname());
/* 182 */         sign = false;
/* 183 */         for (DceInfo d : dceInfoQueryList) {
/* 184 */           if (d.getHostname().equals(systemInfo.getHostname())) {
/* 185 */             sign = true;
/*     */             break;
/*     */           } 
/*     */         } 
/* 189 */         if (sign) {
/*     */           continue;
/*     */         }
/* 192 */         dceInfo.setActive("1");
/* 193 */         dceInfo.setRemark(systemInfo.getRemark());
/* 194 */         dceInfoSaveList.add(dceInfo);
/*     */       } 
/* 196 */       this.dceInfoService.saveRecord(dceInfoSaveList);
/* 197 */     } catch (Exception e) {
/* 198 */       logger.error("将监控主机导入到数通设备列表错误", e);
/* 199 */       this.logInfoService.save("将监控主机导入到数通设备列表错误", e.toString(), "1");
/*     */     } 
/* 201 */     return "sucess";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"edit"})
/*     */   public String edit(Model model, HttpServletRequest request) {
/* 215 */     String errorMsg = "编辑数通设备监测";
/* 216 */     String id = request.getParameter("id");
/* 217 */     DceInfo dceInfo = new DceInfo();
/*     */     try {
/* 219 */       if (StringUtils.isEmpty(id)) {
/* 220 */         model.addAttribute("dceInfo", dceInfo);
/*     */ 
/*     */         
/* 223 */         Map<String, Object> params = new HashMap<>();
/* 224 */         int dbSize = this.dceInfoService.countByParams(params);
/* 225 */         if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 226 */           return "redirect:/dceInfo/list?liceFlage=1";
/*     */         }
/*     */ 
/*     */         
/* 230 */         return "dce/add";
/*     */       } 
/*     */       
/* 233 */       dceInfo = this.dceInfoService.selectById(id);
/* 234 */       model.addAttribute("dceInfo", dceInfo);
/* 235 */     } catch (Exception e) {
/* 236 */       logger.error(errorMsg, e);
/* 237 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 239 */     return "dce/add";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"view"})
/*     */   public String view(Model model, HttpServletRequest request) {
/* 252 */     String errorMsg = "查看数通设备统计图表错误";
/* 253 */     String id = request.getParameter("id");
/* 254 */     String date = request.getParameter("date");
/* 255 */     DceInfo dceInfo = new DceInfo();
/*     */     try {
/* 257 */       dceInfo = this.dceInfoService.selectById(id);
/* 258 */       Map<String, Object> params = new HashMap<>();
/* 259 */       model.addAttribute("dceInfo", dceInfo);
/*     */       
/* 261 */       if (StringUtils.isEmpty(date)) {
/* 262 */         date = DateUtil.getCurrentDate();
/*     */       }
/* 264 */       this.dashboardService.setDateParam(date, params);
/* 265 */       model.addAttribute("datenow", date);
/* 266 */       model.addAttribute("dateList", this.dashboardService.getDateList());
/* 267 */       model.addAttribute("amList", this.dashboardService.getAmList());
/* 268 */       params.put("dceId", dceInfo.getId());
/* 269 */       List<DceState> appStateList = this.dceStateService.selectAllByParams(params);
/* 270 */       model.addAttribute("dceStateList", JSONUtil.parseArray(appStateList));
/* 271 */     } catch (Exception e) {
/* 272 */       logger.error(errorMsg, e);
/* 273 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 275 */     return "dce/view";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 290 */     String errorMsg = "删除数通设备监测错误";
/* 291 */     DceInfo dceInfo = new DceInfo();
/*     */     try {
/* 293 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 294 */         String[] ids = request.getParameter("id").split(",");
/* 295 */         for (String id : ids) {
/* 296 */           dceInfo = this.dceInfoService.selectById(id);
/* 297 */           this.logInfoService.save("删除数通设备监测：" + dceInfo.getHostname(), "删除数通设备监测：" + dceInfo.getHostname() + "备注：" + dceInfo.getRemark(), "0");
/*     */         } 
/* 299 */         this.dceInfoService.deleteById(ids);
/*     */       } 
/* 301 */     } catch (Exception e) {
/* 302 */       logger.error(errorMsg, e);
/* 303 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 305 */     return "redirect:/dceInfo/list";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/DceInfoController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */